package cn.ffcs.uec.outStaffAdjustPostApply.action;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.raptornuke.portal.theme.ThemeDisplay;
import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.common.util.NodeVoUtil;
import cn.ffcs.uec.common.util.UecConstants;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uec.common.vo.UecWaPrmlv;
import cn.ffcs.uec.common.vo.UecWaSeclv;
import cn.ffcs.uec.organization.manager.UecOrgDeptManager;
import cn.ffcs.uec.organization.model.UecOrgDept;
import cn.ffcs.uec.outStaff.manager.UecOutStaffManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.outStaffAdjustPostApply.action.bean.OutStaffAdjustPostApprovalViewMainBean;
import cn.ffcs.uec.post.manager.UecPostManager;
import cn.ffcs.uec.post.model.UecPost;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.manager.ActRunTaskManager;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.salary.manager.UecSalaryProjectManager;
import cn.ffcs.uec.salary.manager.UecWaCrtManager;
import cn.ffcs.uec.salary.model.UecSalaryProject;
import cn.ffcs.uec.salary.model.UecWaCrt;
import cn.ffcs.uec.staff.manager.UecPsndocWadocManager;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.model.UecPsndocWadoc;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;

@Controller
@Scope("prototype")
public class OutStaffAdjustPostApprovalViewMainComposer extends
		BasePortletComposer {

	private static final long serialVersionUID = 8838101945062571937L;

	private OutStaffAdjustPostApprovalViewMainBean bean = new OutStaffAdjustPostApprovalViewMainBean();

	/**
	 * 薪资标准等级 == 岗位等级
	 */
	private UecWaPrmlv uecWaPrmlv = new UecWaPrmlv();
	/**
	 * 薪资标准档别
	 */
	private UecWaSeclv uecWaSeclv = new UecWaSeclv();

	/**
	 * 外包人员基本信息
	 */
	private UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();
	/**
	 * 薪资标准
	 */
	private UecWaCrt uecWaCrt = new UecWaCrt();
	/**
	 * 任职信息
	 */
	private UecPsnjob uecPsnjob;
	/**
	 * 部门
	 */
	private UecOrgDept uecOrgDept;
	/**
	 * 人员类别
	 */
	private UecBdPsncl uecBdPsncl = new UecBdPsncl();
	/**
	 * 薪资变动情况
	 */
	private UecPsndocWadoc uecPsndocWadoc;
	/**
	 * 薪资项目
	 */
	private UecSalaryProject uecSalaryProject = UecSalaryProject.newInstance();
	/**
	 * 岗位基本信息
	 */
	private UecPost uecPost;

	/**
	 * 获取manager
	 */
	private UecWaCrtManager uecWaCrtManager = (UecWaCrtManager) ApplicationContextUtil
			.getBean("uecWaCrtManager");

	private UecPostManager uecPostManager = (UecPostManager) ApplicationContextUtil
			.getBean("uecPostManager");

	private UecSalaryProjectManager uecSalaryProjectManager = (UecSalaryProjectManager) ApplicationContextUtil
			.getBean("uecSalaryProjectManager");

	private UecPsndocWadocManager uecPsndocWadocManager = (UecPsndocWadocManager) ApplicationContextUtil
			.getBean("uecPsndocWadocManager");

	private UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil
			.getBean("uecPsnjobManager");

	private UecOrgDeptManager uecOrgDeptManager = (UecOrgDeptManager) ApplicationContextUtil
			.getBean("uecOrgDeptManager");

	private UecOutStaffManager uecOutStaffManager = (UecOutStaffManager) ApplicationContextUtil
			.getBean("uecOutStaffManager");

	private CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");

	private ActRunTaskManager actRunTaskManager = (ActRunTaskManager) ApplicationContextUtil
			.getBean("actRunTaskManager");

	private String levelPost = "";

	private String taskDefKey;

	private String opType;

	private String taskId;

	private AtiOaBaseObject oaBaseObject;

	@Override
	public String getPortletId() {
		return super.getPortletId();
	}

	@Override
	public ThemeDisplay getThemeDisplay() {
		return super.getThemeDisplay();
	}

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

		this.bean.getUecWaCrtBandboxExt().addForward("onUecWaCrtEditSelected",
				comp, "onUecWaCrtEditSelectedResponse");

	}

	/**
	 * 界面初始化
	 */
	public void onCreate$outStaffAdjustPostApprovalViewWin() {
		bandListbox();
		bindBean();
		bean.getCriterionvalue().setDisabled(true);
		bean.getNmoney().setDisabled(true);
	}

	/**
	 * 监听UecWaCrtBandboxExt抛出的获取选中的薪资标准
	 * 
	 * @param event
	 */
	public void onUecWaCrtEditSelectedResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecWaCrt = (UecWaCrt) event.getOrigin().getData();
			if (null != uecWaCrt) {
				// 判断填入的岗位等级，与原始的岗位等级是否一样
				// if (uecWaCrt.getPostGrade().equals(levelPost)) {
				// 动态设置--标准金额、金额
				if (!StrUtil.isNullOrEmpty(uecWaCrt.getWaCrtMoney())) {
					// 设置标准金额
					bean.getCriterionvalue().setValue(uecWaCrt.getWaCrtMoney());
					// 设置表准金额
					bean.getNmoney().setValue(uecWaCrt.getWaCrtMoney());
				}
				// 设置薪资标准级别
				// 薪资等级==岗位等级
				uecWaPrmlv = new UecWaPrmlv();
				uecWaPrmlv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
				uecWaPrmlv.setLevelName(uecWaCrt.getPostGrade());
				uecWaPrmlv = customFilesManager
						.findObjectByUecWaPrmlv(uecWaPrmlv);
				uecPsndocWadoc.setPkWaPrmlv(uecWaPrmlv.getPkWaPrmlv());

				// 薪资档别
				uecWaSeclv = new UecWaSeclv();
				uecWaSeclv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
				uecWaSeclv.setLevelName(uecWaCrt.getSalaryGrade());
				uecWaSeclv = customFilesManager
						.findObjectByUecWaSeclv(uecWaSeclv);
				uecPsndocWadoc.setPkWaSeclv(uecWaSeclv.getPkWaSeclv());
				// } else {
				// ZkUtil.showInformation("岗位等级只能填：" + levelPost, "温馨提示");
				// bean.getUecWaCrtBandboxExt().setValue(null);
				// }
			}
		}
	}

	/**
	 * 选择是否谈判工资事件 谈判工资=否，薪资标准、标准金额 显示 谈判工资=是，薪资标准、标准金额 不显示
	 */
	public void onCheck$negotiationWage() {
		int index = bean.getNegotiationWage().getSelectedIndex();
		if (0 == index) {
			bean.getPkWaCrtLabel().setVisible(true);
			bean.getUecWaCrtBandboxExt().setVisible(true);
			bean.getApplyCriterionvalueLabel().setVisible(true);
			bean.getCriterionvalue().setVisible(true);
			bean.getCriterionvalue().setDisabled(true);
			bean.getNmoney().setDisabled(true);
			// 切换时清空相应的Textbox
			bean.getUecWaCrtBandboxExt().setValue(null);
			bean.getNmoney().setValue(null);
			bean.getCriterionvalue().setValue(null);
		} else {
			bean.getPkWaCrtLabel().setVisible(false);
			bean.getUecWaCrtBandboxExt().setVisible(false);
			bean.getApplyCriterionvalueLabel().setVisible(false);
			bean.getCriterionvalue().setVisible(false);
			bean.getNmoney().setDisabled(false);
			bean.getNmoney().setValue(null);
			// 切换时清空相应的Textbox
			bean.getUecWaCrtBandboxExt().setValue(null);
			bean.getNmoney().setValue(null);
			bean.getCriterionvalue().setValue(null);
		}
	}

	/**
	 * 重新申请
	 * 
	 * @throws InterruptedException
	 */
	public void onOk() throws InterruptedException {
		// 非查看历史工单
		if (!"onView".equals(opType)) {
			// 判断任务是否已被处理
			boolean isCompleted = ApprovalUtil.isTaskCompleted(oaBaseObject,
					taskId);
			if (isCompleted) {
				onCancel();
				Events.postEvent(ApprovalConstants.ON_REFRESH_QUERY_RESPONSE,
						this.self, null);
				ZkUtil.showError("任务不存在或已被处理完毕！", "错误提示");
				return;
			}
			// 添加校验
			String msg = this.checkUacStaffData();
			if (null != msg) {
				Messagebox.show(msg);
				return;
			}
			Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK
					| Messagebox.CANCEL, Messagebox.QUESTION,
					new EventListener() {
						@Override
						public void onEvent(Event event) throws Exception {
							if (((Integer) event.getData()).intValue() == Messagebox.OK) {
								postApprovalData();
								onCancel();
							} else {
								return;
							}
						}
					});
		} else {
			this.onCancel();
		}
	}

	// 驳回后重新发起流程
	public void postApprovalData() throws InterruptedException {
		PubUtil.fillPoFromEditorBean(uecPsndocWadoc, bean);

		if (!StrUtil.isNullOrEmpty(bean.getApplyBeginDate().getValue())) {
			// 执行日期
			uecPsndocWadoc.setChangedate(DateUtil.dateToStr(bean
					.getApplyBeginDate().getValue()));
		}
		if (!StrUtil.isNullOrEmpty(bean.getEffectDate().getValue())) {
			// 生效日期
			uecPsndocWadoc.setBegindate(DateUtil.dateToStr(bean.getEffectDate()
					.getValue()));
		}
		if (null == bean.getNegotiationWage().getSelectedItem()) {
			ZkUtil.showError("未选择是否谈判工资", "错误提示");
			return;
		}
		// 是否谈判工资
		int index = bean.getNegotiationWage().getSelectedIndex();
		if (0 == index) {
			uecPsndocWadoc.setNegotiationWage("N");
		} else if (1 == index) {
			uecPsndocWadoc.setNegotiationWage("Y");
		} else {
			uecPsndocWadoc.setNegotiationWage(null);
		}
		if (0 == index) {
			// 设置薪资标准级别
			// 薪资等级==岗位等级
			uecWaPrmlv = new UecWaPrmlv();
			uecWaPrmlv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
			uecWaPrmlv.setLevelName(uecWaCrt.getPostGrade());
			uecWaPrmlv = customFilesManager.findObjectByUecWaPrmlv(uecWaPrmlv);
			if (null != uecWaPrmlv) {
				uecPsndocWadoc.setPkWaPrmlv(uecWaPrmlv.getPkWaPrmlv());
			}
			// 薪资档别
			uecWaSeclv = new UecWaSeclv();
			uecWaSeclv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
			uecWaSeclv.setLevelName(uecWaCrt.getSalaryGrade());
			uecWaSeclv = customFilesManager.findObjectByUecWaSeclv(uecWaSeclv);
			if (null != uecWaSeclv) {
				uecPsndocWadoc.setPkWaSeclv(uecWaSeclv.getPkWaSeclv());
			}
			// 标准金额
			if (!StrUtil.isNullOrEmpty(bean.getCriterionvalue().getValue())) {
				uecPsndocWadoc.setCriterionvalue(Double.valueOf(bean
						.getCriterionvalue().getValue()));
			}
		}
		// 金额
		if (StrUtil.isNullOrEmpty(bean.getNmoney().getValue())) {
			ZkUtil.showError("请设置金额", "错误提示");
			return;
		}
		// 变动原因
		uecPsndocWadoc.setPkChangecause((String) bean.getPkChangecause()
				.getSelectedItem().getValue());
		// 备注
		uecPsndocWadoc.setVnote(bean.getVnote().getValue());
		// 依据文件
		uecPsndocWadoc.setVbasefile(bean.getVbasefile().getValue());

		uecPsndocWadoc.setNmoney(Double.valueOf(bean.getNmoney().getValue()));
		DefaultDaoFactory.getDefaultDao().updateObject(uecPsndocWadoc);

		Events.postEvent("onOKResponse", this.self,
				ApprovalConstants.ON_OK_RESULT);

	}

	/**
	 * 审批同意
	 * 
	 * @throws InterruptedException
	 */
	public void onApproval() throws InterruptedException {
		Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK | Messagebox.CANCEL,
				Messagebox.QUESTION, new EventListener() {
					@Override
					public void onEvent(Event event) throws Exception {
						if (((Integer) event.getData()).intValue() == Messagebox.OK) {
							approvalData();
						} else {
							return;
						}
					}
				});
	}

	public void approvalData() {
		Map<String, Object> map = new HashMap<String, Object>();
		String comment = this.getComment(taskDefKey);
		map.put("comment", comment);
		map.put("onApprovalResult", ApprovalConstants.ON_APPROVAL_RESULT);
		Events.postEvent("onApprovalResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 审批拒绝
	 */
	public void onReject() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("comment", this.getComment(taskDefKey));
		map.put("onRejectResult", ApprovalConstants.ON_REJECT_RESULT);
		Events.postEvent("onRejectResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getOutStaffAdjustPostApprovalViewWin().onClose();
	}

	/**
	 * 获取传值
	 * 
	 * @throws ParseException
	 * @throws WrongValueException
	 */
	private void bindBean() {
		String procDefName = (String) arg.get("procDefName");
		this.bean.getOutStaffAdjustPostApprovalViewWin().setTitle(
				procDefName + "审批");

		oaBaseObject = (AtiOaBaseObject) arg.get("oaBaseObject");
		if (!StrUtil.isNullOrEmpty(oaBaseObject)) {
			// 1.获取审批意见
			PubUtil.fillBeanFromPo(oaBaseObject, bean);
		}
		opType = (String) arg.get("opType");
		if ("onView".equals(opType)) {
			// 查看历史工单
			setButtonValid(true, false, false);
			setTextValid(true, true, true);
		} else {

			taskDefKey = (String) arg.get("taskDefKey");
			if ("modify".equals(taskDefKey)) {
				setButtonValid(true, false, false);
				setTextValid(false, false, false);
			} else {
				setButtonValid(false, true, true);
			}
			if ("deptLeaderAudit".equals(taskDefKey)) {
				this.bean.getSecondText().setRows(2);
				this.setTextValid(true, false, false);
				bean.getSecondText().setValue(null);
			}
			if ("hrAudit".equals(taskDefKey)) {
				this.bean.getThirdText().setRows(2);
				this.setTextValid(false, true, false);
				bean.getThirdText().setValue(null);
			}
			if ("hrLeaderAudit".equals(taskDefKey)) {
				this.bean.getFourthText().setRows(2);
				this.setTextValid(false, false, true);
				bean.getFourthText().setValue(null);
			}
		}

		taskId = (String) arg.get("taskId");
		if (null != oaBaseObject) {
			List<Map<String, Object>> list = actRunTaskManager
					.getRuTasks(oaBaseObject.getProcInstId());
			if (null == list) {
				ZkUtil.showError("未知错误!", "错误信息");
				return;
			}
			if (list.size() == 0) {
				String wadocIdTmp = oaBaseObject.getWadocIdHis();
				oaBaseObject.setWadocIdModify(oaBaseObject.getWadocIdHis());
				oaBaseObject.setWadocIdHis(wadocIdTmp);
			}

			// 2.获取人员信息
			String outStaffIdHis = oaBaseObject.getOutStaffIdHis();
			outStaffInfo.setOutStaffId(Long.parseLong(outStaffIdHis));
			outStaffInfo = uecOutStaffManager
					.findUecOutStaffInfoByOutStaffId(outStaffInfo);
			if (null != outStaffInfo) {
				bean.getOutStaffBandboxExt()
						.setValue(outStaffInfo.getPsnCode());
				// 动态设置--姓名
				if (!StrUtil.isNullOrEmpty(outStaffInfo.getPsnName())) {
					bean.getPsnName().setValue(outStaffInfo.getPsnName());
				}

				// 获取--uecPsnjob
				if (!StrUtil.isNullOrEmpty(outStaffInfo.getOutStaffId())) {
					uecPsnjob = new UecPsnjob();
					uecPsnjob.setStaffId(outStaffInfo.getOutStaffId());
					uecPsnjob = uecPsnjobManager.findNewUecPsnjob(uecPsnjob);
					if (!StrUtil.isNullOrEmpty(uecPsnjob)) {
						// 部门
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkDept())) {
							uecOrgDept = new UecOrgDept();
							uecOrgDept.setPkDept(uecPsnjob.getPkDept());
							uecOrgDept = uecOrgDeptManager
									.findUecOrgDeptByOrgDept(uecOrgDept);
							if (null != uecOrgDept
									&& !StrUtil.isNullOrEmpty(uecOrgDept
											.getName())) {
								bean.getDeptName().setValue(
										uecOrgDept.getName());
							}
						}
						// 基准岗位
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getJobglbdef24())) {
							uecPost = new UecPost();
							uecPost.setPkPost(uecPsnjob.getJobglbdef24());
							uecPost = uecPostManager.queryUecPost(uecPost);
							if (null != uecPost) {
								if (!StrUtil.isNullOrEmpty(uecPost
										.getPostname())) {
									bean.getJobName().setValue(
											uecPost.getPostname());
								}
							}
						}
						// 岗位
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getOutJobName())) {
							bean.getJobName().setValue(
									uecPsnjob.getOutJobName());
						}
						// 人员类别
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkPsncl())) {
							uecBdPsncl = new UecBdPsncl();
							uecBdPsncl.setPkPsncl(uecPsnjob.getPkPsncl());
							uecBdPsncl = customFilesManager
									.findUecUecBdPsnclByUecBdPsncl(uecBdPsncl);
							if (!StrUtil.isNullOrEmpty(uecBdPsncl)) {
								if (!StrUtil
										.isNullOrEmpty(uecBdPsncl.getName())) {
									bean.getPkPsncl().setValue(
											uecBdPsncl.getName());
								}
							}
						}
						// 职务
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getJobglbdef4())) {
							bean.getJobGlbdef4().setValue(
									uecPsnjob.getJobglbdef4());
						}
						// 岗位序列：此处岗位序列表--LDAPM_MPW_OM_POSTSERIES中只有两条记录，古此处暂时这样处理
						if ("1001A1100000000006R2".equals(uecPsnjob
								.getPkPostseries())) {
							bean.getPkPostSeries().setValue("管理序列");
						} else if ("1001A1100000000006R3".equals(uecPsnjob
								.getPkPostseries())) {
							bean.getPkPostSeries().setValue("专业序列");
						} else {
							bean.getPkPostSeries().setValue(null);
						}
					}
					// 4.获取uecPsndocWadoc --薪资变动情况表 原数据
					uecPsndocWadoc = new UecPsndocWadoc();
					uecPsndocWadoc.setWadocId(Long.parseLong(oaBaseObject
							.getWadocIdHis()));
					uecPsndocWadoc = uecPsndocWadocManager
							.findUecPsndocWadocById(uecPsndocWadoc);
					// PubUtil.fillBeanFromPo(uecPsndocWadoc, bean);
					// 薪资起始日期=生效日期
					if (null != uecPsndocWadoc) {
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc
								.getBegindate())) {
							bean.getBeginDateHis().setValue(
									uecPsndocWadoc.getBegindate());
						}
						// 薪资项目
						if (!StrUtil
								.isNullOrEmpty(uecPsndocWadoc.getPkWaItem())) {
							uecSalaryProject = new UecSalaryProject();
							uecSalaryProject.getPkWaItem();
							uecSalaryProject = uecSalaryProjectManager
									.findObjectByUecSalaryProject(uecSalaryProject);
							if (null != uecSalaryProject) {
								if (!StrUtil.isNullOrEmpty(uecSalaryProject
										.getName())) {
									bean.getPkWaItemHis().setValue(
											uecSalaryProject.getName());
								}
							}
						}
						// 薪资标准类别
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getPkWaGrd())) {
							if ("1001A1100000000B2DPQ".equals(uecPsndocWadoc
									.getPkWaGrd())) {
								bean.getPkWaGrdHis().setValue("集团薪资标准（新岗新体系）");
							} else if ("1001A1100000000A7FIO"
									.equals(uecPsndocWadoc.getPkWaGrd())) {
								bean.getPkWaGrdHis().setValue("集团薪资标准（旧岗新体系）");
							} else if ("1001A1100000000A83WH"
									.equals(uecPsndocWadoc.getPkWaGrd())) {
								bean.getPkWaGrdHis().setValue("内蒙古薪资标准（旧岗新体系）");
							} else if ("1001A1100000000TRON2"
									.equals(uecPsndocWadoc.getPkWaGrd())) {
								bean.getPkWaGrdHis().setValue("薪资表（旧体系）");
							}
						}
						// 原薪资 是否谈判工资
						bean.getNegotiationWageHis().setValue(
								uecPsndocWadoc.getNegotiationWageName());
						// 原薪资是谈判工资，薪资标准、标准金额不显示
						if ("Y".equals(uecPsndocWadoc.getNegotiationWage())) {
							bean.getPkWaCrtHis().setVisible(false);
							bean.getCriterionvalueHis().setVisible(false);
						}
						// 薪资标准
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc
								.getPkWaSeclv())
								&& !StrUtil.isNullOrEmpty(uecPsndocWadoc
										.getPkWaPrmlv())) {
							// 薪资等级==岗位等级
							uecWaPrmlv = new UecWaPrmlv();
							uecWaPrmlv.setPkWaPrmlv(uecPsndocWadoc
									.getPkWaPrmlv());
							uecWaPrmlv = customFilesManager
									.findObjectByUecWaPrmlv(uecWaPrmlv);
							// 薪资档别
							uecWaSeclv = new UecWaSeclv();
							uecWaSeclv.setPkWaSeclv(uecPsndocWadoc
									.getPkWaSeclv());
							uecWaSeclv = customFilesManager
									.findObjectByUecWaSeclv(uecWaSeclv);
							if (null != uecWaPrmlv && null != uecWaSeclv) {
								if (!StrUtil.isNullOrEmpty(uecWaPrmlv
										.getLevelName())
										&& !StrUtil.isNullOrEmpty(uecWaSeclv
												.getLevelName())) {
									// 设置薪资标准4/A
									uecWaCrt = new UecWaCrt();
									uecWaCrt.setPostGrade(uecWaPrmlv
											.getLevelName());

									// 获取岗位等级
									levelPost = uecWaPrmlv.getLevelName();
									bean.getPostLevel().setValue(levelPost);

									uecWaCrt.setSalaryGrade(uecWaSeclv
											.getLevelName());
									uecWaCrt = uecWaCrtManager
											.findObjectByUecWaCrt(uecWaCrt);
									if (uecWaCrt != null) {
										if (!StrUtil.isNullOrEmpty(uecWaCrt
												.getWaCrtName())) {
											bean.getPkWaCrtHis().setValue(
													uecWaCrt.getWaCrtName());
										}
									}
								}
							}
						}
						// 标准金额
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc
								.getCriterionvalue())) {
							bean.getCriterionvalueHis().setValue(
									String.valueOf(uecPsndocWadoc
											.getCriterionvalue()));
						}
						// 金额
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getNmoney())) {
							bean.getNmoneyHis().setValue(
									String.valueOf(uecPsndocWadoc.getNmoney()));
						}
						// 执行日期
						if (!StrUtil.isNullOrEmpty(uecPsndocWadoc
								.getBegindate())) {
							bean.getBeginDateHis().setValue(
									uecPsndocWadoc.getBegindate());
						}
						// 变动原因
						String changecause = customFilesManager
								.findCustomFilesByPkdefdoc(uecPsndocWadoc
										.getPkChangecause());
						bean.getPkChangecausehis().setValue(changecause);
						// 备注
						bean.getVnotehis().setValue(uecPsndocWadoc.getVnote());
						// 依据文件
						bean.getVbasefileHis().setValue(
								uecPsndocWadoc.getVbasefile());
					}
				}
			}

			String wadocIdAdd = oaBaseObject.getWadocIdAdd();
			// 获取审批中人员薪资信息
			uecPsndocWadoc = new UecPsndocWadoc();
			uecPsndocWadoc.setWadocId(Long.parseLong(wadocIdAdd));
			uecPsndocWadoc = uecPsndocWadocManager
					.findUecPsndocWadocById(uecPsndocWadoc);
			// 是否谈判工资
			if ("N".equals(uecPsndocWadoc.getNegotiationWage())) {
				bean.getNegotiationWage().setSelectedIndex(0);
			} else {
				bean.getNegotiationWage().setSelectedIndex(1);
			}

			// 申请薪资是谈判工资，薪资标准、标准金额不显示
			if ("Y".equals(uecPsndocWadoc.getNegotiationWage())) {
				bean.getPkWaCrtLabel().setVisible(false);
				bean.getUecWaCrtBandboxExt().setVisible(false);
				bean.getApplyCriterionvalueLabel().setVisible(false);
				bean.getCriterionvalue().setVisible(false);
			}
			if (null != uecPsndocWadoc) {
				PubUtil.fillBeanFromPo(uecPsndocWadoc, bean);
				// 备注
				bean.getVnote().setValue(uecPsndocWadoc.getVnote());
			}
			// 生效日期
			if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getBegindate())) {
				bean.getEffectDate()
						.setValue(
								DateUtil.patternStrToDate(uecPsndocWadoc
										.getBegindate()));
			}
			// 执行日期
			if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getChangedate())) {
				bean.getApplyBeginDate().setValue(
						DateUtil.patternStrToDate(uecPsndocWadoc
								.getChangedate()));
			}

			// 薪资标准
			// 判断是否为谈判工资
			if ("N".equals(uecPsndocWadoc.getNegotiationWage())) {
				if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getPkWaSeclv())
						&& !StrUtil
								.isNullOrEmpty(uecPsndocWadoc.getPkWaPrmlv())) {
					// 薪资等级==岗位等级
					uecWaPrmlv = new UecWaPrmlv();
					uecWaPrmlv.setPkWaPrmlv(uecPsndocWadoc.getPkWaPrmlv());
					uecWaPrmlv = customFilesManager
							.findObjectByUecWaPrmlv(uecWaPrmlv);
					// 薪资档别
					uecWaSeclv = new UecWaSeclv();
					uecWaSeclv.setPkWaSeclv(uecPsndocWadoc.getPkWaSeclv());
					uecWaSeclv = customFilesManager
							.findObjectByUecWaSeclv(uecWaSeclv);
					if (null != uecWaPrmlv && null != uecWaSeclv) {
						if (!StrUtil.isNullOrEmpty(uecWaPrmlv.getLevelName())
								&& !StrUtil.isNullOrEmpty(uecWaSeclv
										.getLevelName())) {
							// 设置薪资标准4/A
							uecWaCrt = new UecWaCrt();
							uecWaCrt.setPostGrade(uecWaPrmlv.getLevelName());
							uecWaCrt.setSalaryGrade(uecWaSeclv.getLevelName());
							uecWaCrt = uecWaCrtManager
									.findObjectByUecWaCrt(uecWaCrt);
							if (uecWaCrt != null) {
								if (!StrUtil.isNullOrEmpty(uecWaCrt
										.getWaCrtName())) {
									bean.getUecWaCrtBandboxExt().setValue(
											uecWaCrt.getWaCrtName());
								}
							}
						}
					}
				}
			}

			// 申请原因
			if (!StrUtil.isNullOrEmpty(uecPsndocWadoc.getPkChangecause())) {
				@SuppressWarnings("unchecked")
				List<Listitem> changeCase = bean.getPkChangecause()
						.getChildren();
				for (Listitem listitem : changeCase) {
					if (null != listitem
							&& !StrUtil.isNullOrEmpty(listitem.getValue())) {
						if (listitem
								.getValue()
								.toString()
								.equals(uecPsndocWadoc.getPkChangecause()
										.toString())) {
							bean.getPkChangecause().setSelectedItem(listitem);
						}
					}
				}
			}

		}

	}

	/**
	 * 获取审批意见
	 * 
	 * @param taskDefKey
	 * @return
	 */
	private String getComment(String taskDefKey) {
		if ("deptLeaderAudit".equals(taskDefKey)) {
			return this.bean.getSecondText().getValue();
		}
		if ("hrAudit".equals(taskDefKey)) {
			return this.bean.getThirdText().getValue();
		}
		if ("hrLeaderAudit".equals(taskDefKey)) {
			return this.bean.getFourthText().getValue();
		}
		return null;
	}

	/**
	 * 设置按钮
	 * 
	 * @param canEdit
	 * @param canApproval
	 * @param canReject
	 */
	private void setButtonValid(boolean canEdit, boolean canApproval,
			boolean canReject) {
		this.bean.getOkBtn().setVisible(canEdit);
		this.bean.getOkBtn().setDisabled(!canEdit);

		this.bean.getApprovalBtn().setVisible(canApproval);
		this.bean.getApprovalBtn().setDisabled(!canApproval);

		this.bean.getRejectBtn().setVisible(canReject);
		this.bean.getRejectBtn().setDisabled(!canReject);

	}

	/**
	 * 设置审批意见栏
	 * 
	 * @param secondCanEdit
	 * @param thirdCanEdit
	 * @param fourthCanEdit
	 */
	private void setTextValid(boolean secondCanEdit, boolean thirdCanEdit,
			boolean fourthCanEdit) {
		this.bean.getSecondText().setDisabled(!secondCanEdit);
		this.bean.getThirdText().setDisabled(!thirdCanEdit);
		this.bean.getFourthText().setDisabled(!fourthCanEdit);
	}

	/**
	 * 检测填入的参数是否为空
	 */
	public String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getEffectDate().getValue())) {
			return "请选择生效日期";
		} else if (StrUtil.isNullOrEmpty(bean.getApplyBeginDate().getValue())) {
			return "请选择执行日期";
		}
		// 是否谈判工资
		if (0 == bean.getNegotiationWage().getSelectedIndex()) {
			if (StrUtil.isNullOrEmpty(bean.getUecWaCrtBandboxExt().getValue())) {
				return "请选择薪资标准";
			}
		}
		if (1 == bean.getNegotiationWage().getSelectedIndex()) {
			if (StrUtil.isNullOrEmpty(bean.getNmoney().getValue())) {
				return "请填写金额";
			} else if (StrUtil.checkBlank(bean.getNmoney().getValue())) {
				return "金额中有空格";
			}
		}
		if (StrUtil.isNullOrEmpty(bean.getPkChangecause().getSelectedItem()
				.getValue())) {
			return "请选择变动原因";
		}
		return null;
	}

	private void bandListbox() {
		// 判定变动原因
		ListboxUtils.rendererForEdit(bean.getPkChangecause(),
				NodeVoUtil.getDictionaries(UecConstants.WAGE_CHANGE_CAUSE));
	}

}
